﻿package blob.levelstates
{
    import blob.*;
    import flash.net.*;
    import org.flixel.*;

    public class SplashScreen extends FlxState
    {
        private var thisLevel:PlayState;
        private var nextLevel:PlayState;
        private var thisLevelClass:Class;
        private var nextLevelClass:Class;
        private var results:FlxText;
        private var cont:FlxText;
        private var SO:SharedObject;
        private var savedLevel:PlayState;
        private var bg:FlxSprite;
        private var Bg1:Class;
        private var Bg2:Class;
        private var WinMusic:Class;

        public function SplashScreen()
        {
            this.Bg1 = SplashScreen_Bg1;
            this.Bg2 = SplashScreen_Bg2;
            this.WinMusic = SplashScreen_WinMusic;
            return;
        }// end function

        override public function create() : void
        {
            var _loc_1:FlxSprite = null;
            _loc_1 = new FlxSprite(0, 0, this.Bg1);
            super.create();
            var _loc_2:* = FlxG.play(this.WinMusic, 0.5, true, true);
            _loc_2.fadeIn(0.5);
            this.SO = SharedObject.getLocal("MyGame");
            if (this.SO.size == 0)
            {
                FlxG.levels = new Array(21);
                FlxG.level = 1;
                this.SO.data.levels = FlxG.levels;
                this.SO.flush();
            }
            else
            {
                _loc_1.loadGraphic(this.Bg2);
                FlxG.levels = this.SO.data.levels;
                FlxG.level = this.SO.data.nextLevel;
            }
            add(_loc_1);
            return;
        }// end function

        override public function update() : void
        {
            if (FlxG.keys.SPACE)
            {
                if (this.getLevel(FlxG.level) != null)
                {
                    FlxG.switchState(this.getLevel(FlxG.level));
                }
                else
                {
                    FlxG.switchState(this.getLevel(1));
                }
                this.kill();
            }
            else if (FlxG.keys.justPressed("M"))
            {
                FlxG.switchState(new GameMenu());
                this.kill();
            }
            return;
        }// end function

        public function getLevel(param1:Number) : PlayState
        {
            switch(param1)
            {
                case 1:
                {
                    return new LevelState1();
                }
                case 2:
                {
                    return new LevelState2();
                }
                case 3:
                {
                    return new LevelState3();
                }
                case 4:
                {
                    return new LevelState4();
                }
                case 5:
                {
                    return new LevelState5();
                }
                case 6:
                {
                    return new LevelState6();
                }
                case 7:
                {
                    return new LevelState7();
                }
                case 8:
                {
                    return new LevelState8();
                }
                case 9:
                {
                    return new LevelState9();
                }
                case 10:
                {
                    return new LevelState10();
                }
                case 11:
                {
                    return new LevelState11();
                }
                case 12:
                {
                    return new LevelState12();
                }
                case 13:
                {
                    return new LevelState13();
                }
                case 14:
                {
                    return new LevelState14();
                }
                case 15:
                {
                    return new LevelState15();
                }
                case 16:
                {
                    return new LevelState16();
                }
                case 17:
                {
                    return new LevelState17();
                }
                case 18:
                {
                    return new LevelState18();
                }
                case 19:
                {
                    return new LevelState19();
                }
                case 20:
                {
                    return new LevelState20();
                }
                default:
                {
                    return null;
                    break;
                }
            }
        }// end function

    }
}
